-
Notifications
You must be signed in to change notification settings - Fork 84
(feat)O3-2971: Adding conformation modal for an empty form. #464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
I made many changes to the form-factory-provider , I would like it to be reviewed in case it can be designed better @NethmiRodrigo @samuelmale @denniskigen |
Reated PR: |
I made the changes according to the discussion in the JIRA, can it be reviewed again @denniskigen @samuelmale @NethmiRodrigo |
// Validate all forms | ||
const isValid = forms.every((formContext) => validateForm(formContext)); | ||
// Check if the form is empty | ||
const isEmpty = forms.every((formContext) => validateEmptyForm(formContext)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to evaluate isEmpty
if the form is invalid.
if (isEmpty && isValid) { | ||
if (handleEmptyFormSubmission && typeof handleEmptyFormSubmission === 'function') { | ||
try { | ||
await handleEmptyFormSubmission(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should basically launch a modal prompting the user. Based on the user's decision, we should either save an empty encounter by submitting the form or close the form. Here is an example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in the current scenario the user is not allowed to submit empty forms, thus there is no saving the form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair! In either case, we should expect handleEmptyFormSubmission
to promise some kind of boolean value; true
we discard the form otherwise we continue editing. If the promise is rejected -- continue editing the form.
@@ -46,6 +46,11 @@ export function validateForm(context: FormContextProps) { | |||
return errors.length === 0; | |||
} | |||
|
|||
export function validateEmptyForm(context: FormContextProps) { | |||
const { methods: { formState: { dirtyFields } } } = context; | |||
return Object.keys(dirtyFields).length === 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you filter out transient fields?
Requirements
Summary
This PR adds a feature which triggers a conformation modal when User submits an empty form.
Screenshots
OpenMRS.-.Google.Chrome.2025-02-11.23-09-36.mp4
Related Issue
Other